package com.woniuxy.dr_mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dr_mall.entity.DrUserFavorite;
import com.woniuxy.dr_mall.mapper.DrUserFavoriteMapper;
import com.woniuxy.dr_mall.service.IDrUserFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
@Service
public class DrUserFavoriteServiceImpl extends ServiceImpl<DrUserFavoriteMapper, DrUserFavorite> implements IDrUserFavoriteService {
    @Autowired
    DrUserFavoriteMapper drUserFavoriteMapper;
    //通过用户id商品id对用户的收藏信息进行删除 叶官鑫 2021-8-16
    @Override
    public void deleteFavorite(int userId, int productId) {
         drUserFavoriteMapper.deleteFavorite(userId,productId);
    }

    @Override
    public void add(Integer userId, Integer pid) {
        DrUserFavorite userFavorite=new DrUserFavorite();
        userFavorite.setUserId(userId);
        userFavorite.setProductId(pid);
        userFavorite.setTime(new SimpleDateFormat("yyyy-MM-dd HH:dd:mm").format(new Date()));
        drUserFavoriteMapper.add(userFavorite);
    }
}
